
-- --------------------------------------------------
-- Entity Designer DDL Script for SQL Server 2005, 2008, and Azure
-- --------------------------------------------------
-- Date Created: 02/07/2012 20:08:53
-- Generated from EDMX file: C:\Users\psli50.PASSARINISUAREZ\Desktop\Promocotfinal.web\Promocot\Models\ClientomaticDB.edmx
-- --------------------------------------------------

SET QUOTED_IDENTIFIER OFF;
GO
USE [clientomatic];
GO
IF SCHEMA_ID(N'dbo') IS NULL EXECUTE(N'CREATE SCHEMA [dbo]');
GO

-- --------------------------------------------------
-- Dropping existing FOREIGN KEY constraints
-- --------------------------------------------------

IF OBJECT_ID(N'[dbo].[FK_RolRol_Transaccion]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Rol_TransaccionSet] DROP CONSTRAINT [FK_RolRol_Transaccion];
GO
IF OBJECT_ID(N'[dbo].[FK_TransaccionRol_Transaccion]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Rol_TransaccionSet] DROP CONSTRAINT [FK_TransaccionRol_Transaccion];
GO
IF OBJECT_ID(N'[dbo].[FK_UsuarioBitacora]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[BitacoraSet] DROP CONSTRAINT [FK_UsuarioBitacora];
GO
IF OBJECT_ID(N'[dbo].[FK_TransaccionBitacora]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[BitacoraSet] DROP CONSTRAINT [FK_TransaccionBitacora];
GO
IF OBJECT_ID(N'[dbo].[FK_EmpresaUsuario]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[UsuarioSet] DROP CONSTRAINT [FK_EmpresaUsuario];
GO
IF OBJECT_ID(N'[dbo].[FK_EmpresaClasificacion]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[ClasificacionSet] DROP CONSTRAINT [FK_EmpresaClasificacion];
GO
IF OBJECT_ID(N'[dbo].[FK_EmpresaRecurso]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[RecursoSet] DROP CONSTRAINT [FK_EmpresaRecurso];
GO
IF OBJECT_ID(N'[dbo].[FK_EmpresaProovedor]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[ProovedorSet] DROP CONSTRAINT [FK_EmpresaProovedor];
GO
IF OBJECT_ID(N'[dbo].[FK_ProovedorPromocion]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[PromocionSet] DROP CONSTRAINT [FK_ProovedorPromocion];
GO
IF OBJECT_ID(N'[dbo].[FK_UsuarioPromocion]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[PromocionSet] DROP CONSTRAINT [FK_UsuarioPromocion];
GO
IF OBJECT_ID(N'[dbo].[FK_EmpresaPromocion]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[PromocionSet] DROP CONSTRAINT [FK_EmpresaPromocion];
GO
IF OBJECT_ID(N'[dbo].[FK_PromocionPromocion_Status]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Promocion_StatusSet] DROP CONSTRAINT [FK_PromocionPromocion_Status];
GO
IF OBJECT_ID(N'[dbo].[FK_ClasificacionPromocion]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[PromocionSet] DROP CONSTRAINT [FK_ClasificacionPromocion];
GO
IF OBJECT_ID(N'[dbo].[FK_MonedaPromocion]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[PromocionSet] DROP CONSTRAINT [FK_MonedaPromocion];
GO
IF OBJECT_ID(N'[dbo].[FK_PromocionCostopromocion]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[CostopromocionSet] DROP CONSTRAINT [FK_PromocionCostopromocion];
GO
IF OBJECT_ID(N'[dbo].[FK_MonedaCostopromocion]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[CostopromocionSet] DROP CONSTRAINT [FK_MonedaCostopromocion];
GO
IF OBJECT_ID(N'[dbo].[FK_PromocionTemporada_Promocion]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[PromocionTemporada] DROP CONSTRAINT [FK_PromocionTemporada_Promocion];
GO
IF OBJECT_ID(N'[dbo].[FK_PromocionTemporada_Temporada]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[PromocionTemporada] DROP CONSTRAINT [FK_PromocionTemporada_Temporada];
GO
IF OBJECT_ID(N'[dbo].[FK_EmpresaTemporada]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[TemporadaSet] DROP CONSTRAINT [FK_EmpresaTemporada];
GO
IF OBJECT_ID(N'[dbo].[FK_DestinoPromocion]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[PromocionSet] DROP CONSTRAINT [FK_DestinoPromocion];
GO
IF OBJECT_ID(N'[dbo].[FK_UsuarioCotizacion]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[CotizacionSet] DROP CONSTRAINT [FK_UsuarioCotizacion];
GO
IF OBJECT_ID(N'[dbo].[FK_CotizacionRecurso]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[RecursoSet] DROP CONSTRAINT [FK_CotizacionRecurso];
GO
IF OBJECT_ID(N'[dbo].[FK_TemporadaCotizacion]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[CotizacionSet] DROP CONSTRAINT [FK_TemporadaCotizacion];
GO
IF OBJECT_ID(N'[dbo].[FK_ClienteCotizacion]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[CotizacionSet] DROP CONSTRAINT [FK_ClienteCotizacion];
GO
IF OBJECT_ID(N'[dbo].[FK_PromocionCotizacion_Promocion]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[PromocionCotizacion] DROP CONSTRAINT [FK_PromocionCotizacion_Promocion];
GO
IF OBJECT_ID(N'[dbo].[FK_PromocionCotizacion_Cotizacion]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[PromocionCotizacion] DROP CONSTRAINT [FK_PromocionCotizacion_Cotizacion];
GO
IF OBJECT_ID(N'[dbo].[FK_DestinoCotizacion]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[CotizacionSet] DROP CONSTRAINT [FK_DestinoCotizacion];
GO
IF OBJECT_ID(N'[dbo].[FK_EmpresaDestino]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[DestinoSet] DROP CONSTRAINT [FK_EmpresaDestino];
GO
IF OBJECT_ID(N'[dbo].[FK_UsuarioRol1]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[UsuarioSet] DROP CONSTRAINT [FK_UsuarioRol1];
GO

-- --------------------------------------------------
-- Dropping existing tables
-- --------------------------------------------------

IF OBJECT_ID(N'[dbo].[UsuarioSet]', 'U') IS NOT NULL
    DROP TABLE [dbo].[UsuarioSet];
GO
IF OBJECT_ID(N'[dbo].[RolSet]', 'U') IS NOT NULL
    DROP TABLE [dbo].[RolSet];
GO
IF OBJECT_ID(N'[dbo].[TransaccionSet]', 'U') IS NOT NULL
    DROP TABLE [dbo].[TransaccionSet];
GO
IF OBJECT_ID(N'[dbo].[Rol_TransaccionSet]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Rol_TransaccionSet];
GO
IF OBJECT_ID(N'[dbo].[BitacoraSet]', 'U') IS NOT NULL
    DROP TABLE [dbo].[BitacoraSet];
GO
IF OBJECT_ID(N'[dbo].[EmpresaSet]', 'U') IS NOT NULL
    DROP TABLE [dbo].[EmpresaSet];
GO
IF OBJECT_ID(N'[dbo].[ClasificacionSet]', 'U') IS NOT NULL
    DROP TABLE [dbo].[ClasificacionSet];
GO
IF OBJECT_ID(N'[dbo].[RecursoSet]', 'U') IS NOT NULL
    DROP TABLE [dbo].[RecursoSet];
GO
IF OBJECT_ID(N'[dbo].[ProovedorSet]', 'U') IS NOT NULL
    DROP TABLE [dbo].[ProovedorSet];
GO
IF OBJECT_ID(N'[dbo].[PromocionSet]', 'U') IS NOT NULL
    DROP TABLE [dbo].[PromocionSet];
GO
IF OBJECT_ID(N'[dbo].[MonedaSet]', 'U') IS NOT NULL
    DROP TABLE [dbo].[MonedaSet];
GO
IF OBJECT_ID(N'[dbo].[Promocion_StatusSet]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Promocion_StatusSet];
GO
IF OBJECT_ID(N'[dbo].[CostopromocionSet]', 'U') IS NOT NULL
    DROP TABLE [dbo].[CostopromocionSet];
GO
IF OBJECT_ID(N'[dbo].[TemporadaSet]', 'U') IS NOT NULL
    DROP TABLE [dbo].[TemporadaSet];
GO
IF OBJECT_ID(N'[dbo].[DestinoSet]', 'U') IS NOT NULL
    DROP TABLE [dbo].[DestinoSet];
GO
IF OBJECT_ID(N'[dbo].[CotizacionSet]', 'U') IS NOT NULL
    DROP TABLE [dbo].[CotizacionSet];
GO
IF OBJECT_ID(N'[dbo].[ClienteSet]', 'U') IS NOT NULL
    DROP TABLE [dbo].[ClienteSet];
GO
IF OBJECT_ID(N'[dbo].[PromocionTemporada]', 'U') IS NOT NULL
    DROP TABLE [dbo].[PromocionTemporada];
GO
IF OBJECT_ID(N'[dbo].[PromocionCotizacion]', 'U') IS NOT NULL
    DROP TABLE [dbo].[PromocionCotizacion];
GO

-- --------------------------------------------------
-- Creating all tables
-- --------------------------------------------------

-- Creating table 'UsuarioSet'
CREATE TABLE [dbo].[UsuarioSet] (
    [cod_usuario] int IDENTITY(1,1) NOT NULL,
    [nombre] nvarchar(max)  NOT NULL,
    [descripcion] nvarchar(max)  NOT NULL,
    [email] nvarchar(max)  NOT NULL,
    [observaciones] nvarchar(max)  NOT NULL,
    [activo] bit  NOT NULL,
    [password] nvarchar(max)  NOT NULL,
    [pregunta_olvido_password] nvarchar(max)  NOT NULL,
    [respuesta_olvido_password] nvarchar(max)  NOT NULL,
    [salt] bit  NOT NULL,
    [cod_recordatorio] nvarchar(max)  NOT NULL,
    [cod_recordatorio_encriptado] nvarchar(max)  NOT NULL,
    [cod_empresa] int  NOT NULL,
    [login] nvarchar(max)  NOT NULL,
    [apellido] nvarchar(max)  NULL,
    [telefono] nvarchar(max)  NOT NULL,
    [RolSet_cod_rol] int  NOT NULL,
    [Departamento_Id] int  NOT NULL
);
GO

-- Creating table 'RolSet'
CREATE TABLE [dbo].[RolSet] (
    [cod_rol] int IDENTITY(1,1) NOT NULL,
    [nombre] nvarchar(max)  NOT NULL,
    [descripcion] nvarchar(max)  NOT NULL,
    [query_asociado_a] nvarchar(max)  NOT NULL
);
GO

-- Creating table 'TransaccionSet'
CREATE TABLE [dbo].[TransaccionSet] (
    [cod_transaccion] int IDENTITY(1,1) NOT NULL,
    [nombre] nvarchar(max)  NOT NULL,
    [descripcion] nvarchar(max)  NOT NULL,
    [grupo] nvarchar(max)  NOT NULL,
    [requiere_confirmacion] nvarchar(max)  NOT NULL
);
GO

-- Creating table 'Rol_TransaccionSet'
CREATE TABLE [dbo].[Rol_TransaccionSet] (
    [cod_rol_transaccion] int IDENTITY(1,1) NOT NULL,
    [cod_rol] int  NOT NULL,
    [cod_transaccion] int  NOT NULL
);
GO

-- Creating table 'BitacoraSet'
CREATE TABLE [dbo].[BitacoraSet] (
    [cod_bitacora] int IDENTITY(1,1) NOT NULL,
    [cod_usuario] int  NOT NULL,
    [cod_transaccion] int  NOT NULL,
    [observaciones] nvarchar(max)  NOT NULL,
    [fecha_hora] datetime  NOT NULL
);
GO

-- Creating table 'EmpresaSet'
CREATE TABLE [dbo].[EmpresaSet] (
    [cod_empresa] int IDENTITY(1,1) NOT NULL,
    [nombre_empresa] nvarchar(max)  NOT NULL
);
GO

-- Creating table 'ClasificacionSet'
CREATE TABLE [dbo].[ClasificacionSet] (
    [cod_clasificacion] int IDENTITY(1,1) NOT NULL,
    [tipo] real  NOT NULL,
    [nombre] nvarchar(max)  NOT NULL,
    [nivel] bit  NOT NULL,
    [cod_clasificacion_padre] int  NULL,
    [cod_empresa] int  NOT NULL
);
GO

-- Creating table 'RecursoSet'
CREATE TABLE [dbo].[RecursoSet] (
    [cod_recurso] int IDENTITY(1,1) NOT NULL,
    [cod_empresa] int  NOT NULL,
    [cod_clasificacion] int  NOT NULL,
    [nombre] nvarchar(max)  NOT NULL,
    [direccion] nvarchar(max)  NOT NULL,
    [tipo] real  NOT NULL,
    [solo_usado_en_tipo] real  NOT NULL,
    [solo_usado_en_cod] int  NOT NULL,
    [Cotizacion_Id] int  NOT NULL
);
GO

-- Creating table 'ProovedorSet'
CREATE TABLE [dbo].[ProovedorSet] (
    [cod_proveedor] int IDENTITY(1,1) NOT NULL,
    [nombre] nvarchar(max)  NOT NULL,
    [descripcion] nvarchar(max)  NOT NULL,
    [cod_empresa] int  NOT NULL
);
GO

-- Creating table 'PromocionSet'
CREATE TABLE [dbo].[PromocionSet] (
    [cod_promocion] int IDENTITY(1,1) NOT NULL,
    [tags] nvarchar(max)  NULL,
    [orden] smallint  NULL,
    [tarifa_consolidada_moneda] int  NOT NULL,
    [tarifa_consolidada] float  NOT NULL,
    [tarifa_consolidada_tipo] nvarchar(max)  NOT NULL,
    [titulo] nvarchar(max)  NOT NULL,
    [subtitulo] nvarchar(max)  NOT NULL,
    [descripcion] nvarchar(max)  NOT NULL,
    [valida_desde] datetime  NOT NULL,
    [valida_hasta] datetime  NOT NULL,
    [activa] real  NULL,
    [cod_proveedor] int  NOT NULL,
    [cod_empresa] int  NOT NULL,
    [cod_usuario] int  NOT NULL,
    [status] nvarchar(max)  NULL,
    [cod_clasificacion] int  NOT NULL,
    [grupo] nvarchar(max)  NULL,
    [eliminado] bit  NOT NULL,
    [Destino_Id] int  NOT NULL
);
GO

-- Creating table 'MonedaSet'
CREATE TABLE [dbo].[MonedaSet] (
    [cod_moneda] int IDENTITY(1,1) NOT NULL,
    [nombre] nvarchar(max)  NOT NULL,
    [abreviacion] nvarchar(max)  NOT NULL
);
GO

-- Creating table 'Promocion_StatusSet'
CREATE TABLE [dbo].[Promocion_StatusSet] (
    [cod_promocion_status] int IDENTITY(1,1) NOT NULL,
    [observacion] nvarchar(max)  NOT NULL,
    [cod_promocion] int  NOT NULL,
    [fecha_hora] datetime  NOT NULL
);
GO

-- Creating table 'CostopromocionSet'
CREATE TABLE [dbo].[CostopromocionSet] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [descripcion] nvarchar(max)  NULL,
    [monto] float  NULL,
    [cod_promocion] int  NOT NULL,
    [cod_moneda] int  NOT NULL
);
GO

-- Creating table 'TemporadaSet'
CREATE TABLE [dbo].[TemporadaSet] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [nombre_temporada] nvarchar(max)  NOT NULL,
    [fecha_inicio] datetime  NULL,
    [fecha_fin] datetime  NULL,
    [Empresa_cod_empresa] int  NOT NULL
);
GO

-- Creating table 'DestinoSet'
CREATE TABLE [dbo].[DestinoSet] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [nombre_destino] nvarchar(max)  NOT NULL,
    [num_destino] smallint  NOT NULL,
    [Empresa_cod_empresa] int  NOT NULL
);
GO

-- Creating table 'CotizacionSet'
CREATE TABLE [dbo].[CotizacionSet] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [titulo_cotizacion] nvarchar(max)  NOT NULL,
    [texto_intro] nvarchar(max)  NOT NULL,
    [precio_referencial] nvarchar(max)  NULL,
    [descripcion_html] nvarchar(max)  NOT NULL,
    [status] nvarchar(max)  NOT NULL,
    [year] smallint  NOT NULL,
    [observaciones] nvarchar(max)  NULL,
    [incluye] nvarchar(max)  NULL,
    [noincluye] nvarchar(max)  NULL,
    [eliminado] bit  NOT NULL,
    [fecha] datetime  NOT NULL,
    [fecha_inicio] datetime  NULL,
    [noches] smallint  NOT NULL,
    [fecha_fin] datetime  NULL,
    [formateado] bit  NOT NULL,
    [eshijode] int  NOT NULL,
    [imagenes_adicionales] nvarchar(max)  NULL,
    [comentario] nvarchar(max)  NULL,
    [Usuario_cod_usuario] int  NOT NULL,
    [Temporada_Id] int  NOT NULL,
    [Cliente_Id] int  NULL,
    [Destino_Id] int  NOT NULL
);
GO

-- Creating table 'ClienteSet'
CREATE TABLE [dbo].[ClienteSet] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Nombre] nvarchar(max)  NOT NULL,
    [email] nvarchar(max)  NOT NULL,
    [sexo] nvarchar(max)  NOT NULL
);
GO

-- Creating table 'DepartamentoSet'
CREATE TABLE [dbo].[DepartamentoSet] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [nombre] nvarchar(max)  NOT NULL
);
GO

-- Creating table 'PromocionTemporada'
CREATE TABLE [dbo].[PromocionTemporada] (
    [Promocion_cod_promocion] int  NOT NULL,
    [Temporada_Id] int  NOT NULL
);
GO

-- Creating table 'PromocionCotizacion'
CREATE TABLE [dbo].[PromocionCotizacion] (
    [Promocion_cod_promocion] int  NOT NULL,
    [Cotizacion_Id] int  NOT NULL
);
GO

-- --------------------------------------------------
-- Creating all PRIMARY KEY constraints
-- --------------------------------------------------

-- Creating primary key on [cod_usuario] in table 'UsuarioSet'
ALTER TABLE [dbo].[UsuarioSet]
ADD CONSTRAINT [PK_UsuarioSet]
    PRIMARY KEY CLUSTERED ([cod_usuario] ASC);
GO

-- Creating primary key on [cod_rol] in table 'RolSet'
ALTER TABLE [dbo].[RolSet]
ADD CONSTRAINT [PK_RolSet]
    PRIMARY KEY CLUSTERED ([cod_rol] ASC);
GO

-- Creating primary key on [cod_transaccion] in table 'TransaccionSet'
ALTER TABLE [dbo].[TransaccionSet]
ADD CONSTRAINT [PK_TransaccionSet]
    PRIMARY KEY CLUSTERED ([cod_transaccion] ASC);
GO

-- Creating primary key on [cod_rol_transaccion] in table 'Rol_TransaccionSet'
ALTER TABLE [dbo].[Rol_TransaccionSet]
ADD CONSTRAINT [PK_Rol_TransaccionSet]
    PRIMARY KEY CLUSTERED ([cod_rol_transaccion] ASC);
GO

-- Creating primary key on [cod_bitacora] in table 'BitacoraSet'
ALTER TABLE [dbo].[BitacoraSet]
ADD CONSTRAINT [PK_BitacoraSet]
    PRIMARY KEY CLUSTERED ([cod_bitacora] ASC);
GO

-- Creating primary key on [cod_empresa] in table 'EmpresaSet'
ALTER TABLE [dbo].[EmpresaSet]
ADD CONSTRAINT [PK_EmpresaSet]
    PRIMARY KEY CLUSTERED ([cod_empresa] ASC);
GO

-- Creating primary key on [cod_clasificacion] in table 'ClasificacionSet'
ALTER TABLE [dbo].[ClasificacionSet]
ADD CONSTRAINT [PK_ClasificacionSet]
    PRIMARY KEY CLUSTERED ([cod_clasificacion] ASC);
GO

-- Creating primary key on [cod_recurso] in table 'RecursoSet'
ALTER TABLE [dbo].[RecursoSet]
ADD CONSTRAINT [PK_RecursoSet]
    PRIMARY KEY CLUSTERED ([cod_recurso] ASC);
GO

-- Creating primary key on [cod_proveedor] in table 'ProovedorSet'
ALTER TABLE [dbo].[ProovedorSet]
ADD CONSTRAINT [PK_ProovedorSet]
    PRIMARY KEY CLUSTERED ([cod_proveedor] ASC);
GO

-- Creating primary key on [cod_promocion] in table 'PromocionSet'
ALTER TABLE [dbo].[PromocionSet]
ADD CONSTRAINT [PK_PromocionSet]
    PRIMARY KEY CLUSTERED ([cod_promocion] ASC);
GO

-- Creating primary key on [cod_moneda] in table 'MonedaSet'
ALTER TABLE [dbo].[MonedaSet]
ADD CONSTRAINT [PK_MonedaSet]
    PRIMARY KEY CLUSTERED ([cod_moneda] ASC);
GO

-- Creating primary key on [cod_promocion_status] in table 'Promocion_StatusSet'
ALTER TABLE [dbo].[Promocion_StatusSet]
ADD CONSTRAINT [PK_Promocion_StatusSet]
    PRIMARY KEY CLUSTERED ([cod_promocion_status] ASC);
GO

-- Creating primary key on [Id] in table 'CostopromocionSet'
ALTER TABLE [dbo].[CostopromocionSet]
ADD CONSTRAINT [PK_CostopromocionSet]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'TemporadaSet'
ALTER TABLE [dbo].[TemporadaSet]
ADD CONSTRAINT [PK_TemporadaSet]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'DestinoSet'
ALTER TABLE [dbo].[DestinoSet]
ADD CONSTRAINT [PK_DestinoSet]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'CotizacionSet'
ALTER TABLE [dbo].[CotizacionSet]
ADD CONSTRAINT [PK_CotizacionSet]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'ClienteSet'
ALTER TABLE [dbo].[ClienteSet]
ADD CONSTRAINT [PK_ClienteSet]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'DepartamentoSet'
ALTER TABLE [dbo].[DepartamentoSet]
ADD CONSTRAINT [PK_DepartamentoSet]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Promocion_cod_promocion], [Temporada_Id] in table 'PromocionTemporada'
ALTER TABLE [dbo].[PromocionTemporada]
ADD CONSTRAINT [PK_PromocionTemporada]
    PRIMARY KEY NONCLUSTERED ([Promocion_cod_promocion], [Temporada_Id] ASC);
GO

-- Creating primary key on [Promocion_cod_promocion], [Cotizacion_Id] in table 'PromocionCotizacion'
ALTER TABLE [dbo].[PromocionCotizacion]
ADD CONSTRAINT [PK_PromocionCotizacion]
    PRIMARY KEY NONCLUSTERED ([Promocion_cod_promocion], [Cotizacion_Id] ASC);
GO

-- --------------------------------------------------
-- Creating all FOREIGN KEY constraints
-- --------------------------------------------------

-- Creating foreign key on [cod_rol] in table 'Rol_TransaccionSet'
ALTER TABLE [dbo].[Rol_TransaccionSet]
ADD CONSTRAINT [FK_RolRol_Transaccion]
    FOREIGN KEY ([cod_rol])
    REFERENCES [dbo].[RolSet]
        ([cod_rol])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_RolRol_Transaccion'
CREATE INDEX [IX_FK_RolRol_Transaccion]
ON [dbo].[Rol_TransaccionSet]
    ([cod_rol]);
GO

-- Creating foreign key on [cod_transaccion] in table 'Rol_TransaccionSet'
ALTER TABLE [dbo].[Rol_TransaccionSet]
ADD CONSTRAINT [FK_TransaccionRol_Transaccion]
    FOREIGN KEY ([cod_transaccion])
    REFERENCES [dbo].[TransaccionSet]
        ([cod_transaccion])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_TransaccionRol_Transaccion'
CREATE INDEX [IX_FK_TransaccionRol_Transaccion]
ON [dbo].[Rol_TransaccionSet]
    ([cod_transaccion]);
GO

-- Creating foreign key on [cod_usuario] in table 'BitacoraSet'
ALTER TABLE [dbo].[BitacoraSet]
ADD CONSTRAINT [FK_UsuarioBitacora]
    FOREIGN KEY ([cod_usuario])
    REFERENCES [dbo].[UsuarioSet]
        ([cod_usuario])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_UsuarioBitacora'
CREATE INDEX [IX_FK_UsuarioBitacora]
ON [dbo].[BitacoraSet]
    ([cod_usuario]);
GO

-- Creating foreign key on [cod_transaccion] in table 'BitacoraSet'
ALTER TABLE [dbo].[BitacoraSet]
ADD CONSTRAINT [FK_TransaccionBitacora]
    FOREIGN KEY ([cod_transaccion])
    REFERENCES [dbo].[TransaccionSet]
        ([cod_transaccion])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_TransaccionBitacora'
CREATE INDEX [IX_FK_TransaccionBitacora]
ON [dbo].[BitacoraSet]
    ([cod_transaccion]);
GO

-- Creating foreign key on [cod_empresa] in table 'UsuarioSet'
ALTER TABLE [dbo].[UsuarioSet]
ADD CONSTRAINT [FK_EmpresaUsuario]
    FOREIGN KEY ([cod_empresa])
    REFERENCES [dbo].[EmpresaSet]
        ([cod_empresa])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_EmpresaUsuario'
CREATE INDEX [IX_FK_EmpresaUsuario]
ON [dbo].[UsuarioSet]
    ([cod_empresa]);
GO

-- Creating foreign key on [cod_empresa] in table 'ClasificacionSet'
ALTER TABLE [dbo].[ClasificacionSet]
ADD CONSTRAINT [FK_EmpresaClasificacion]
    FOREIGN KEY ([cod_empresa])
    REFERENCES [dbo].[EmpresaSet]
        ([cod_empresa])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_EmpresaClasificacion'
CREATE INDEX [IX_FK_EmpresaClasificacion]
ON [dbo].[ClasificacionSet]
    ([cod_empresa]);
GO

-- Creating foreign key on [cod_empresa] in table 'RecursoSet'
ALTER TABLE [dbo].[RecursoSet]
ADD CONSTRAINT [FK_EmpresaRecurso]
    FOREIGN KEY ([cod_empresa])
    REFERENCES [dbo].[EmpresaSet]
        ([cod_empresa])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_EmpresaRecurso'
CREATE INDEX [IX_FK_EmpresaRecurso]
ON [dbo].[RecursoSet]
    ([cod_empresa]);
GO

-- Creating foreign key on [cod_empresa] in table 'ProovedorSet'
ALTER TABLE [dbo].[ProovedorSet]
ADD CONSTRAINT [FK_EmpresaProovedor]
    FOREIGN KEY ([cod_empresa])
    REFERENCES [dbo].[EmpresaSet]
        ([cod_empresa])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_EmpresaProovedor'
CREATE INDEX [IX_FK_EmpresaProovedor]
ON [dbo].[ProovedorSet]
    ([cod_empresa]);
GO

-- Creating foreign key on [cod_proveedor] in table 'PromocionSet'
ALTER TABLE [dbo].[PromocionSet]
ADD CONSTRAINT [FK_ProovedorPromocion]
    FOREIGN KEY ([cod_proveedor])
    REFERENCES [dbo].[ProovedorSet]
        ([cod_proveedor])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_ProovedorPromocion'
CREATE INDEX [IX_FK_ProovedorPromocion]
ON [dbo].[PromocionSet]
    ([cod_proveedor]);
GO

-- Creating foreign key on [cod_usuario] in table 'PromocionSet'
ALTER TABLE [dbo].[PromocionSet]
ADD CONSTRAINT [FK_UsuarioPromocion]
    FOREIGN KEY ([cod_usuario])
    REFERENCES [dbo].[UsuarioSet]
        ([cod_usuario])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_UsuarioPromocion'
CREATE INDEX [IX_FK_UsuarioPromocion]
ON [dbo].[PromocionSet]
    ([cod_usuario]);
GO

-- Creating foreign key on [cod_empresa] in table 'PromocionSet'
ALTER TABLE [dbo].[PromocionSet]
ADD CONSTRAINT [FK_EmpresaPromocion]
    FOREIGN KEY ([cod_empresa])
    REFERENCES [dbo].[EmpresaSet]
        ([cod_empresa])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_EmpresaPromocion'
CREATE INDEX [IX_FK_EmpresaPromocion]
ON [dbo].[PromocionSet]
    ([cod_empresa]);
GO

-- Creating foreign key on [cod_promocion] in table 'Promocion_StatusSet'
ALTER TABLE [dbo].[Promocion_StatusSet]
ADD CONSTRAINT [FK_PromocionPromocion_Status]
    FOREIGN KEY ([cod_promocion])
    REFERENCES [dbo].[PromocionSet]
        ([cod_promocion])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_PromocionPromocion_Status'
CREATE INDEX [IX_FK_PromocionPromocion_Status]
ON [dbo].[Promocion_StatusSet]
    ([cod_promocion]);
GO

-- Creating foreign key on [cod_clasificacion] in table 'PromocionSet'
ALTER TABLE [dbo].[PromocionSet]
ADD CONSTRAINT [FK_ClasificacionPromocion]
    FOREIGN KEY ([cod_clasificacion])
    REFERENCES [dbo].[ClasificacionSet]
        ([cod_clasificacion])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_ClasificacionPromocion'
CREATE INDEX [IX_FK_ClasificacionPromocion]
ON [dbo].[PromocionSet]
    ([cod_clasificacion]);
GO

-- Creating foreign key on [tarifa_consolidada_moneda] in table 'PromocionSet'
ALTER TABLE [dbo].[PromocionSet]
ADD CONSTRAINT [FK_MonedaPromocion]
    FOREIGN KEY ([tarifa_consolidada_moneda])
    REFERENCES [dbo].[MonedaSet]
        ([cod_moneda])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_MonedaPromocion'
CREATE INDEX [IX_FK_MonedaPromocion]
ON [dbo].[PromocionSet]
    ([tarifa_consolidada_moneda]);
GO

-- Creating foreign key on [cod_promocion] in table 'CostopromocionSet'
ALTER TABLE [dbo].[CostopromocionSet]
ADD CONSTRAINT [FK_PromocionCostopromocion]
    FOREIGN KEY ([cod_promocion])
    REFERENCES [dbo].[PromocionSet]
        ([cod_promocion])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_PromocionCostopromocion'
CREATE INDEX [IX_FK_PromocionCostopromocion]
ON [dbo].[CostopromocionSet]
    ([cod_promocion]);
GO

-- Creating foreign key on [cod_moneda] in table 'CostopromocionSet'
ALTER TABLE [dbo].[CostopromocionSet]
ADD CONSTRAINT [FK_MonedaCostopromocion]
    FOREIGN KEY ([cod_moneda])
    REFERENCES [dbo].[MonedaSet]
        ([cod_moneda])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_MonedaCostopromocion'
CREATE INDEX [IX_FK_MonedaCostopromocion]
ON [dbo].[CostopromocionSet]
    ([cod_moneda]);
GO

-- Creating foreign key on [Promocion_cod_promocion] in table 'PromocionTemporada'
ALTER TABLE [dbo].[PromocionTemporada]
ADD CONSTRAINT [FK_PromocionTemporada_Promocion]
    FOREIGN KEY ([Promocion_cod_promocion])
    REFERENCES [dbo].[PromocionSet]
        ([cod_promocion])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- Creating foreign key on [Temporada_Id] in table 'PromocionTemporada'
ALTER TABLE [dbo].[PromocionTemporada]
ADD CONSTRAINT [FK_PromocionTemporada_Temporada]
    FOREIGN KEY ([Temporada_Id])
    REFERENCES [dbo].[TemporadaSet]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_PromocionTemporada_Temporada'
CREATE INDEX [IX_FK_PromocionTemporada_Temporada]
ON [dbo].[PromocionTemporada]
    ([Temporada_Id]);
GO

-- Creating foreign key on [Empresa_cod_empresa] in table 'TemporadaSet'
ALTER TABLE [dbo].[TemporadaSet]
ADD CONSTRAINT [FK_EmpresaTemporada]
    FOREIGN KEY ([Empresa_cod_empresa])
    REFERENCES [dbo].[EmpresaSet]
        ([cod_empresa])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_EmpresaTemporada'
CREATE INDEX [IX_FK_EmpresaTemporada]
ON [dbo].[TemporadaSet]
    ([Empresa_cod_empresa]);
GO

-- Creating foreign key on [Destino_Id] in table 'PromocionSet'
ALTER TABLE [dbo].[PromocionSet]
ADD CONSTRAINT [FK_DestinoPromocion]
    FOREIGN KEY ([Destino_Id])
    REFERENCES [dbo].[DestinoSet]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_DestinoPromocion'
CREATE INDEX [IX_FK_DestinoPromocion]
ON [dbo].[PromocionSet]
    ([Destino_Id]);
GO

-- Creating foreign key on [Usuario_cod_usuario] in table 'CotizacionSet'
ALTER TABLE [dbo].[CotizacionSet]
ADD CONSTRAINT [FK_UsuarioCotizacion]
    FOREIGN KEY ([Usuario_cod_usuario])
    REFERENCES [dbo].[UsuarioSet]
        ([cod_usuario])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_UsuarioCotizacion'
CREATE INDEX [IX_FK_UsuarioCotizacion]
ON [dbo].[CotizacionSet]
    ([Usuario_cod_usuario]);
GO

-- Creating foreign key on [Cotizacion_Id] in table 'RecursoSet'
ALTER TABLE [dbo].[RecursoSet]
ADD CONSTRAINT [FK_CotizacionRecurso]
    FOREIGN KEY ([Cotizacion_Id])
    REFERENCES [dbo].[CotizacionSet]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_CotizacionRecurso'
CREATE INDEX [IX_FK_CotizacionRecurso]
ON [dbo].[RecursoSet]
    ([Cotizacion_Id]);
GO

-- Creating foreign key on [Temporada_Id] in table 'CotizacionSet'
ALTER TABLE [dbo].[CotizacionSet]
ADD CONSTRAINT [FK_TemporadaCotizacion]
    FOREIGN KEY ([Temporada_Id])
    REFERENCES [dbo].[TemporadaSet]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_TemporadaCotizacion'
CREATE INDEX [IX_FK_TemporadaCotizacion]
ON [dbo].[CotizacionSet]
    ([Temporada_Id]);
GO

-- Creating foreign key on [Cliente_Id] in table 'CotizacionSet'
ALTER TABLE [dbo].[CotizacionSet]
ADD CONSTRAINT [FK_ClienteCotizacion]
    FOREIGN KEY ([Cliente_Id])
    REFERENCES [dbo].[ClienteSet]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_ClienteCotizacion'
CREATE INDEX [IX_FK_ClienteCotizacion]
ON [dbo].[CotizacionSet]
    ([Cliente_Id]);
GO

-- Creating foreign key on [Promocion_cod_promocion] in table 'PromocionCotizacion'
ALTER TABLE [dbo].[PromocionCotizacion]
ADD CONSTRAINT [FK_PromocionCotizacion_Promocion]
    FOREIGN KEY ([Promocion_cod_promocion])
    REFERENCES [dbo].[PromocionSet]
        ([cod_promocion])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- Creating foreign key on [Cotizacion_Id] in table 'PromocionCotizacion'
ALTER TABLE [dbo].[PromocionCotizacion]
ADD CONSTRAINT [FK_PromocionCotizacion_Cotizacion]
    FOREIGN KEY ([Cotizacion_Id])
    REFERENCES [dbo].[CotizacionSet]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_PromocionCotizacion_Cotizacion'
CREATE INDEX [IX_FK_PromocionCotizacion_Cotizacion]
ON [dbo].[PromocionCotizacion]
    ([Cotizacion_Id]);
GO

-- Creating foreign key on [Destino_Id] in table 'CotizacionSet'
ALTER TABLE [dbo].[CotizacionSet]
ADD CONSTRAINT [FK_DestinoCotizacion]
    FOREIGN KEY ([Destino_Id])
    REFERENCES [dbo].[DestinoSet]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_DestinoCotizacion'
CREATE INDEX [IX_FK_DestinoCotizacion]
ON [dbo].[CotizacionSet]
    ([Destino_Id]);
GO

-- Creating foreign key on [Empresa_cod_empresa] in table 'DestinoSet'
ALTER TABLE [dbo].[DestinoSet]
ADD CONSTRAINT [FK_EmpresaDestino]
    FOREIGN KEY ([Empresa_cod_empresa])
    REFERENCES [dbo].[EmpresaSet]
        ([cod_empresa])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_EmpresaDestino'
CREATE INDEX [IX_FK_EmpresaDestino]
ON [dbo].[DestinoSet]
    ([Empresa_cod_empresa]);
GO

-- Creating foreign key on [RolSet_cod_rol] in table 'UsuarioSet'
ALTER TABLE [dbo].[UsuarioSet]
ADD CONSTRAINT [FK_UsuarioRol1]
    FOREIGN KEY ([RolSet_cod_rol])
    REFERENCES [dbo].[RolSet]
        ([cod_rol])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_UsuarioRol1'
CREATE INDEX [IX_FK_UsuarioRol1]
ON [dbo].[UsuarioSet]
    ([RolSet_cod_rol]);
GO

-- Creating foreign key on [Departamento_Id] in table 'UsuarioSet'
ALTER TABLE [dbo].[UsuarioSet]
ADD CONSTRAINT [FK_DepartamentoUsuario]
    FOREIGN KEY ([Departamento_Id])
    REFERENCES [dbo].[DepartamentoSet]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_DepartamentoUsuario'
CREATE INDEX [IX_FK_DepartamentoUsuario]
ON [dbo].[UsuarioSet]
    ([Departamento_Id]);
GO

-- --------------------------------------------------
-- Script has ended
-- --------------------------------------------------